<template>
    <div id="sureorder">
        <van-nav-bar title="确认订单" left-text="返回" left-arrow @click-left="onClickLeft" fixed />
        <div class="space"></div>
        <div class="pad40">
            <div class="selectparent">
                <div class="sp_child" @click="goAddress">
                    <div class="address_img">
                        <div class="img_container"><img src="../../assets/icon/icon_addr.png" alt="">
                            <div class="img_word"></div>
                        </div>
                        <div class="address_text">
                            <div>
                                收货地址： {{ address }}
                            </div>
                            <div>
                                姓名：{{ name }}
                            </div>
                            <div>
                                手机号：{{ phone }}
                            </div>
                        </div>
                    </div>
                    <div class="clickmore"><img src="../../assets/icon/icon_my_jt.png" alt=""></div>
                </div>

                <div class="sp_child">
                    <div class="address_img">
                        <div class="img_container"><img src="../../assets/icon/icon_wuliu.png" alt="">
                            <div class="img_word">配送</div>
                        </div>
                        <div class="address_text">
                            <van-radio-group v-model="checked" direction="horizontal" checked-color="#18AAA2">
                                <van-radio name="1" label-position="left">免费上门取货</van-radio>
                                <van-radio name="2" label-position="left">自己送达</van-radio>
                            </van-radio-group>
                        </div>
                    </div>
                </div>

                <div class="sp_child">
                    <div class="address_img">
                        <div class="img_container"><img src="../../assets/icon/icon_time.png" alt="">
                            <div class="img_word">上门</div>
                        </div>
                        <div class="address_text">请选择预约上门取货时间</div>
                    </div>
                    <div class="clickmore"><img src="../../assets/icon/icon_my_jt.png" alt=""></div>
                    <van-cell is-link title="不知道" @click="showgo('time')"
                        style="width: 300px;opacity: 0; position: absolute;" />
                    <van-action-sheet v-model="showtime" title="选择预约时间">
                        <div class="content_time">
                            <div class="ct_check">
                                <van-radio-group v-model="checked2" direction="horizontal" checked-color="#18AAA2">
                                    <van-radio name="1" label-position="left">今天</van-radio>
                                    <van-radio name="2" label-position="left">明天</van-radio>
                                </van-radio-group>
                            </div>

                            <div class="time_select">

                            </div>
                        </div>


                    </van-action-sheet>
                </div>
            </div>

            <!-- 订单信息 -->

            <div class="pro_info">
                <div>订单信息</div>
                <div class="pro_list" v-for="(item, index) of listData" :key="item.pro_id">
                    <div class="pro_img"><img :src="item.pro_img" alt=""></div>
                    <div class="pro_detail">
                        <div class="pd_top">{{ item.pro_title }}</div>
                    </div>
                    <div class="pro_buy">
                        <div class="pb_price">￥{{ item.pro_price }}</div>
                        <div class="pb_mount">X{{ item.pro_num }}</div>
                    </div>
                </div>
            </div>

            <div class="discount">

                <div class="sp_child">
                    <div class="address_img">
                        <div class="address_text">优惠卡券</div>
                    </div>
                    <div class="clickmore"><img src="../../assets/icon/icon_my_jt.png" alt=""></div>
                    <van-cell is-link title="优惠卡券" @click="showgo('kaquan')" style="opacity: 0; position: absolute;" />
                    <van-action-sheet v-model="show" title="标题" height="50vh">
                        <div class="content">我勒个卡券</div>
                    </van-action-sheet>
                </div>

                <div class="notice">
                    <div class="notice_title">订单备注</div>
                    <div class="notice_content"><textarea name="" id="" placeholder="您给干洗店师傅的留言-选填"
                            v-model="remark"></textarea></div>
                </div>

            </div>

            <div class="option">

                <div class="option_child">
                    <van-cell is-link title="可选范围" @click="showgo('option1')" round="true"
                        style="width: 100%; border-radius: 30px 30px 0 0;" />
                    <van-action-sheet v-model="show1" title="标题">
                        <div class="content">选范围</div>
                    </van-action-sheet>
                </div>
                <div class="option_child">
                    <van-cell is-link title="时效&运费说明" @click="showgo('option2')" round="true"
                        style="width: 100%; border-radius: 30px 30px 0 0;" />
                    <van-action-sheet v-model="show2" title="标题">
                        <div class="content">时效&运费说明</div>
                    </van-action-sheet>
                </div>
                <div class="option_child">
                    <van-cell is-link title="不知道" @click="showgo('option3')" round="true"
                        style="width: 100%; border-radius:0 0 30px 30px;" />
                    <van-action-sheet v-model="show3" title="标题">
                        <div class="content">不知道</div>
                    </van-action-sheet>
                </div>

            </div>
            <footer class="cate-footer">
                <div class="total">共计:￥ {{ totalPrice }}</div>
                <button type="button" class="pay" @click='goSure'>立即预约</button>
            </footer>
        </div>
    </div>
</template>




<script lang="ts" setup>
import { computed, ref } from 'vue';
import { httpPostToken } from '../../utils/request'
import router from '@/router';
import { useRoute } from 'vue-router';

const route = useRoute();
// console.log(route.query);

// 选中产品的数据的回填

interface ProductItem {
    pro_id: number;
    pro_img: string;
    pro_title: string;
    pro_price: number;
    pro_num: number;
}
const listData = ref<ProductItem[]>([]);

//取出我们存的数据
let json: any = localStorage.getItem('json');
let jsonArr: any = JSON.parse(json);

listData.value = jsonArr
// 收货地址
const address: any = ref('');
const name: any = ref('');
const phone: any = ref('');

if (route.query == null) {
    address.value = "添加地址"
    name.value = "添加姓名"
    phone.value = "添加手机号"
} else {
    address.value = route.query.address;
    name.value = route.query.name;
    phone.value = route.query.phone;
}

//


// 获取所有订单接口 *token   get token /api/order  status4

const addressId = ref(null);

const item = ref({
    pro_num: 0,
    pro_id: 0,
});

const params: any = ref([])


////
const onClickLeft = () => history.back();
const checked = ref('1');
const checked2 = ref('1');
const show = ref(false);
const show1 = ref(false);
const show2 = ref(false);
const show3 = ref(false);
const showtime = ref(false);
const showgo = (a: string) => {
    if (a == 'option1') {
        show1.value = true
    } else if (a == 'kaquan') {
        show.value = true
    } else if (a == 'option2') {
        show2.value = true
    } else if (a == 'option3') {
        show3.value = true
    } else if (a == 'time') {
        showtime.value = true
    }
}

//跳转地址 goAddress
const goAddress = () => {
    router.push({
        path: '/introduct'
    })
}

const remark = ref("");
const goSure = async () => {
    // let obj = [{
    //     address_id:route.query.address_id
    // }]
    // listData.value.push({
    //     address_id: route.query.address_id,
    //     status:0,
    //     remark:remark.value
    // })
    listData.value.forEach((item: any) => {
        item.address_id = route.query.address_id;
        item.status = 0;
        item.remark = remark.value;
    });
    console.log(listData.value);
    let res: any = await httpPostToken('/api/order', 'post', { orderJson: JSON.stringify(listData.value) })
    if (res.status === 200) {
        router.push('/order')
    }
}

//计算
const totalPrice = computed(() => {
    let total = 0;
    listData.value.forEach((item: any) => {

        total += item.pro_price * item.pro_num;

    });
    return total;
});

</script>







<style lang="less" scoped>
.content_time {
    margin: 50px 40px;

    .ct_check {
        width: 100%;
        padding: 0 200px;
        display: flex;
        justify-content: space-between;
    }
}

/deep/.van-popup--bottom {
    height: 60%;
}

/deep/.van-cell {
    width: 500px;
}

.content {
    padding: 16px 16px 160px;
}

#sureorder {
    width: 100vw;
    // height: 100vh;
    background-color: #f5f5f5;

    .space {
        height: 92px;
    }

    .pad40 {
        width: 86vw;

        margin: 0 7vw;
        background-color: #F5F5F5;

        .selectparent {
            width: 100%;
            height: 420px;
            background-color: #fff;
            margin-top: 30px;
            border-radius: 30px;
            display: flex;
            flex-direction: column;
            justify-content: space-around;

            .sp_child {
                display: flex;
                justify-content: space-between;
                padding: 30px 20px;

                .address_img {
                    display: flex;
                    justify-content: space-between;

                    .img_container {
                        width: 70px;
                        height: 70px;
                        background-color: #18AAA2;
                        border-radius: 50%;

                        img {
                            width: 50%;
                            height: 50%;
                            padding: 25% 25%;
                        }

                        .img_word {
                            width: 70px;
                            text-align: center;
                            background-color: #FF6F49;
                            font-size: 20px;
                            color: #fff;
                            border-radius: 30px;
                            margin-top: -20px;

                        }
                    }

                    .address_text {
                        // margin-top: 23px;
                        font-size: 27px;
                        margin-left: 20px;
                    }

                }

                .clickmore {
                    margin-top: 23px;
                }

            }
        }

        .pro_info {
            background-color: #fff;
            margin-top: 30px;
            border-radius: 30px;
            padding: 30px 20px;

            .pro_list {
                display: flex;
                justify-content: space-between;
                margin-top: 20px;

                .pro_img {
                    width: 130px;
                    height: 130px;
                    background-color: red;

                    img {
                        width: 100%;
                        height: 100%;
                    }
                }

                .pro_detail {
                    height: 130px;

                    .pd_top {
                        font-size: 27px;
                    }

                    .pd_bot {
                        font-size: 27px;
                        // margin-top: 10px;
                    }
                }

                .pro_buy {
                    .pb_price {
                        font-size: 40px;
                    }

                    .pb_mount {
                        text-align: right;
                        color: #A1A1A1;
                    }
                }
            }
        }

        .discount {
            height: 300px;
            background-color: #fff;
            margin-top: 30px;
            border-radius: 30px;
            padding: 15px 20px;

            .sp_child {
                display: flex;
                justify-content: space-between;
                // padding: 15px 20px;

                .address_img {
                    display: flex;
                    justify-content: space-between;

                    .address_text {
                        margin-top: 23px;
                        font-size: 27px;
                        margin-left: 20px;
                    }

                }

                .clickmore {
                    margin-top: 26px;
                }

            }

            .notice {
                display: flex;
                justify-content: space-between;
                margin-left: 20px;
                margin-top: 30px;
                width: 90%;

                .notice_title {
                    font-size: 27px;
                }

                .notice_content {
                    width: 400px;

                    textarea {
                        width: 100%;
                        height: 100px;
                        background-color: #f5f5f5;
                        border: none;
                        font-size: 27px;
                    }
                }
            }
        }

        .option {
            background-color: #fff;
            margin-top: 20px;
            border-radius: 30px;
            margin-bottom: 120px;
        }
    }
}

.cate-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
    background: #18AAA2;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .total {
        color: #fff;

    }

    .pay {
        border: none;
        outline: none;
        background: #fff;
        border-radius: 30px;
        padding: 10px 30px;
    }
}
</style>